#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
    File Name:      easy_trader_test
    Author:         'daze'
    date:           2018/12/19
    description:    可以直接交易
"""

import easytrader
from easytrader import helpers

"""
初始化跟踪的 trader
"""
# 雪球客户端
xq_initial_assets = 3000
xq_user = easytrader.use('xq', initial_assets=xq_initial_assets)
# 配置文件路径
xq_user.prepare('../config/xq_client.json')


# 跟踪 joinquant / ricequant 的模拟交易
def follow_joinquant_ricequant():
    """
    初始化跟踪 joinquant / ricequant 的 follower
    """
    target = 'jq'  # joinquant
    follower = easytrader.follower(target)
    follower.login(user='15811455931', password='qwertzxcv0')

    """
    连接 follower 和 trader
    """
    follower.follow(xq_user,
                    'https://www.joinquant.com/algorithm/live/index?backtestId=2b77f7afe843fc6ddc8efd6574898fbc')


# 跟踪 雪球的组合
def follow_xq_combine():
    """
    初始化跟踪 雪球组合 的 follower
    """
    xq_follower = easytrader.follower('xq')
    xq_follower.login(
        cookies='xq_a_token.sig=CoFzisEpUBVZUXIH80jgYl0aGeY; xq_r_token.sig=bGXk935CYJh5r9TyOJSQP09JOHU; Hm_lvt_1db88642e346389874251b5a1eded6e3=1545288759; device_id=128b00ad45ae490d9715bccc90513a9d; _ga=GA1.2.539013607.1545288762; _gid=GA1.2.461024773.1545288762; s=fg111syk2y; xq_a_token=f4f1b76544c306d6367be5ab17d89d003168f1af; xqat=f4f1b76544c306d6367be5ab17d89d003168f1af; xq_r_token=91fe0d4e12a2d3508ccc2c11b3624e6bb83f2266; xq_is_login=1; u=1934267639; _gat_gtag_UA_16079156_4=1; Hm_lpvt_1db88642e346389874251b5a1eded6e3=1545289529')

    """
    连接 follower 和 trader
    """
    xq_follower.follow(xq_user, 'ZH1739147', initial_assets=xq_initial_assets)  # 一直在输出，不知道 follow 啥呢


def get_xq_client_info():
    print('xq balance=' + str(xq_user.balance))
    # 返回
    # {
    #     "asset_balance": asset_balance,
    #     "current_balance": cash,
    #     "enable_balance": cash,
    #     "market_value": market,
    #     "money_type": u"人民币",
    #     "pre_interest": 0.25,
    # }


def get_new_stock_infos():
    ipo_data = helpers.get_today_ipo_data()
    print('今天可以申购的新股信息' + str(ipo_data))


def auto_fight_new():
    print('开始自动打新')
    xq_user.auto_ipo()  # 雪球客户端没有自动打新


# follow_xq_combine()
# get_xq_client_info()
# auto_fight_new()
get_new_stock_infos()
